package gui.main_menu;
import gui.single_game.gui.SingleGameTeamSelect;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import main.CyclingManager;

public class MainMenuLayout implements ActionListener {
	
	private JFrame frame;
	private JButton careerButton, singleGameButton, ridersButton;
	private JPanel panel;
	private Font font = new Font("Times New Roman", 1, 40);
	private CyclingManager cyclingManager;

	public MainMenuLayout(int width, int height, CyclingManager cyclingManager) {
		
		this.cyclingManager = cyclingManager;

		GridBagLayout layout = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.BOTH;
		int layoutWidth = 200, layoutHeigth = 70;
		layout.columnWidths = new int[] { layoutWidth, layoutWidth+100, layoutWidth };
		layout.rowHeights = new int[] { layoutHeigth+100, layoutHeigth, layoutHeigth, layoutHeigth, layoutHeigth, layoutHeigth, 
				layoutHeigth, layoutHeigth, layoutHeigth, layoutHeigth };
		
		frame = new JFrame();
		frame.setSize(width, height);
		frame.setTitle("Cycling Manager - Main Menu");
		frame.setVisible(true);
		frame.setResizable(false);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLayout(new GridLayout(1,0));
		
		panel = new JPanel(layout); 
		
		c.gridx = 1;   c.gridy = 1;
		careerButton = new JButton("Career");
		careerButton.setOpaque(true);
		careerButton.setFont(font);
		careerButton.setBackground(Color.orange);
		panel.add(careerButton, c);		
		
		c.gridy = 3;
		singleGameButton = new JButton("Single Game");
		singleGameButton.setOpaque(true);
		singleGameButton.setFont(font);
		singleGameButton.addActionListener(this);
		singleGameButton.setBackground(Color.orange);
		panel.add(singleGameButton, c);
		
		c.gridy = 5;
		ridersButton = new JButton("Cyclist");
		ridersButton.setOpaque(true);
		ridersButton.setFont(font);
		ridersButton.setBackground(Color.orange);
		ridersButton.addActionListener(this);
		panel.add(ridersButton, c);
		frame.add(panel);	
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		
		Object src = e.getSource();
		
		if (src == singleGameButton) {
			new SingleGameTeamSelect(frame, cyclingManager.cyclists, cyclingManager.teams);
		}
		else if (src == ridersButton) {
			new SearchRiders(frame, cyclingManager.cyclists);
		}
		
	}	
}
